package net.myspring.middle.validator;

import net.myspring.common.utils.ValidationUtils;
import net.myspring.middle.domain.Menu;
import net.myspring.middle.mapper.MenuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
 * Created by liuj on 2016-08-29.
 */
@Component
public class MenuValidator implements Validator {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public boolean supports(Class<?> clazz) {
        return Menu.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        Menu menu = (Menu) target;
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "error.name", "菜单名称不能为空");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "hidden", "error.hidden", "菜单是否隐藏不能为空");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "sort", "error.sort", "菜单排序不能为空");
    }
}
